package pluginUtils;

import java.util.ArrayList;

public class Polynome {
	private ArrayList<Monome> lesMonomes=new ArrayList<Monome>();
	
	public void add(Monome n){
		this.lesMonomes.add(n);
	}
	
	public Complexe eval(Complexe z){
		Complexe resu=Complexe.ZERO; 
		for(Monome m:this.lesMonomes){
			resu=Complexe.sum(resu,m.eval(z));
		}
		return resu;
	}
	
	public String toString(){
		String s=""; 
		for(Monome m:this.lesMonomes)
			s+=m+" "; 
		return s; 
	}
	
	public Polynome derive(){
		Polynome resu=new Polynome(); 
		for(Monome m:this.lesMonomes)
			if(m.getExponent()!=0)resu.add(new Monome(m.getCoef()*m.getExponent(),m.getExponent()-1));
		return resu;
	}
	
	public Polynome dSecond(){
		return this.derive().derive();
	}

}
